package com.wms.shop.service.impl;

import java.util.List;
import java.util.Arrays;
import com.wms.common.core.utils.DateUtils;
import com.wms.shop.domain.OrderItem;
import com.wms.shop.mapper.OrderItemMapper;
import com.wms.shop.service.IOrderItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.wms.common.core.utils.SecurityUtils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

/**
 * 订单明细Service业务层处理
 *
 * @author zzm
 * @date 2021-12-19
 */
@Service
public class OrderItemServiceImpl implements IOrderItemService
{
    @Autowired
    private OrderItemMapper orderItemMapper;

    /**
     * 查询订单明细
     *
     * @param id 订单明细ID
     * @return 订单明细
     */
    @Override
    public OrderItem selectOrderItemById(Long id)
    {
        return orderItemMapper.selectById(id);
    }

    /**
     * 查询订单明细列表
     *
     * @param orderItem 订单明细
     * @return 订单明细
     */
    @Override
    public List<OrderItem> selectOrderItemList(OrderItem orderItem)
    {
        QueryWrapper queryWrapper = new QueryWrapper();
        return orderItemMapper.selectList(queryWrapper);
    }

    /**
     * 新增订单明细
     *
     * @param orderItem 订单明细
     * @return 结果
     */
    @Override
    public int insertOrderItem(OrderItem orderItem)
    {
        orderItem.setDelFlag(false);
        orderItem.setCreateBy(SecurityUtils.getUsername());
        orderItem.setCreateTime(DateUtils.getNowDate());
        return orderItemMapper.insert(orderItem);
    }

    /**
     * 修改订单明细
     *
     * @param orderItem 订单明细
     * @return 结果
     */
    @Override
    public int updateOrderItem(OrderItem orderItem)
    {
        orderItem.setUpdateBy(SecurityUtils.getUsername());
        orderItem.setUpdateTime(DateUtils.getNowDate());
        return orderItemMapper.updateById(orderItem);
    }

    /**
     * 批量删除订单明细
     *
     * @param ids 需要删除的订单明细ID
     * @return 结果
     */
    @Override
    public int deleteOrderItemByIds(Long[] ids)
    {
        OrderItem orderItem = new OrderItem();
        orderItem.setDelFlag(Boolean.TRUE);
        orderItem.setUpdateTime(DateUtils.getNowDate());
        orderItem.setUpdateBy(SecurityUtils.getUsername());
        QueryWrapper<OrderItem> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("id",Arrays.asList(ids));
        return orderItemMapper.update(orderItem, queryWrapper);
    }

    /**
     * 删除订单明细信息
     *
     * @param id 订单明细ID
     * @return 结果
     */
    @Override
    public int deleteOrderItemById(Long id)
    {
        return orderItemMapper.deleteById(id);
    }
}
